﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace T.S.BaseData.Api.Controllers
{
    /// <summary>
    /// 上传图片控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UploadController : ControllerBase
    {

        /// <summary>
        /// 上传图片 
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public string FileUpload(IFormFile file)
        {
            var path = Directory.GetCurrentDirectory() + @"\wwwroot\images\" + file.FileName;
            using (var stream = new FileStream(path,FileMode.Create))
            {
                file.CopyTo(stream);
                stream.Flush();
            }
            return "images/" + file.FileName;
        }
        
    }
}
